package uni.UNIBEE7B8D.Presenter;

import com.google.gson.Gson;

import org.json.JSONException;

import java.text.ParseException;

import uni.UNIBEE7B8D.CommonTool.HttpUrl;
import uni.UNIBEE7B8D.CommonTool.OkHttpUtil;
import uni.UNIBEE7B8D.Enty.HomeMenu;
import uni.UNIBEE7B8D.Enty.HomeZhibo;
import uni.UNIBEE7B8D.view.Study.Zhibo.ZhiboList.ZhiboListContract;

public class ZhiboListPersenter implements ZhiboListContract.ZhiboListPersenter {

    ZhiboListContract.ZhiboListView zhiboListView;

    public ZhiboListPersenter(ZhiboListContract.ZhiboListView zhiboListView) {
        this.zhiboListView = zhiboListView;
    }

    @Override
    public void getList() {
        new OkHttpUtil().getJson(HttpUrl.daohang +"?column=rank&order=asc", new OkHttpUtil.HttpCallBack() {
            @Override
            public void onSusscess(String data) throws JSONException, ParseException {
                HomeMenu homeMenu = new Gson().fromJson(data,HomeMenu.class);
                if(homeMenu.isSuccess()){
                    zhiboListView.GetMeny(homeMenu);
                }else {
                    zhiboListView.Toast(homeMenu.getMessage());
                }
            }
        });
    }

    @Override
    public void GetZhibo() {
        new OkHttpUtil().getJson(HttpUrl.homeZhibo, new OkHttpUtil.HttpCallBack() {
            @Override
            public void onSusscess(String data) throws JSONException, ParseException {
                HomeZhibo homeZhibo = new Gson().fromJson(data,HomeZhibo.class);
                if(homeZhibo.isSuccess()){
                    zhiboListView.GetZhibo(homeZhibo);
                }else{
                    zhiboListView.Toast(homeZhibo.getMessage());
                }
            }
        });
    }
}
